/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.purpose.controller;

import com.koron.purpose.utils.BusinessCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.swan.bean.MessageBean;

import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.permission.SPIAccountAnno;
import com.koron.purpose.bean.SafetyDirectorAssessmentBean;
import com.koron.purpose.service.api.SafetyDirectorAssessmentService;
import com.koron.system.annotation.Log;
import com.koron.system.discrete.BusinessManipulation;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "directorAssessment", description = "安全主任考核")
@RestController
@RequestMapping("/directorAssessment")
public class SafetyDirectorAssessmentController {
    @Autowired
    private SafetyDirectorAssessmentService service;

    @ApiOperation("删除")
    @ApiImplicitParam(name = "id", value = "id",  paramType = "query", dataType = "String")
    @RequestMapping(value = "/delete.htm", method = {RequestMethod.POST})
    @Log(title = "删除安全主任考核单", businessModule = "安全主任考核", businessManipulation = BusinessManipulation.DELETE)
    public MessageBean<?> delete(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String id) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.delete(id);
    }

    @ApiOperation("详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userCode", value = "当前用户code",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "id", value = "id",  paramType = "query", dataType = "String")})
    @RequestMapping(value = "/details.htm", method = {RequestMethod.GET})
    public MessageBean<?> details(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String userCode, String id) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.details(userCode, id);
    }


    @ApiOperation("新增安全主任考核")
    @RequestMapping(value = "/insert.htm", method = {RequestMethod.POST})
    @Log(title = "新增安全主任考核", businessModule = "安全主任考核", businessManipulation = BusinessManipulation.INSERT)
    public MessageBean<?> insert(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestBody SafetyDirectorAssessmentBean bean) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.insert(bean, user);
    }

    @ApiOperation("修改安全主任考核")
    @RequestMapping(value = "/update.htm", method = {RequestMethod.POST})
    @Log(title = "修改安全主任考核", businessModule = "安全主任考核", businessManipulation = BusinessManipulation.UPDATE)
    public MessageBean<?> update(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestBody SafetyDirectorAssessmentBean bean) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.update(bean, user);
    }

    @ApiOperation("查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "公司code",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "userCode", value = "当前用户code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "month", value = "年月",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "staffName", value = "考核人名称",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "assessmentType", value = "考核类型：1月2季3年",  paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "corpType", value = "公司类型：1公司2水务",  paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "fstatusflag", value = "单据流程状态：0草稿1审批中2审批通过",  paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "page", value = "当前页",  paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数",  paramType = "query", dataType = "Integer")})
    @RequestMapping(value = "/query.htm", method = {RequestMethod.GET})
    public MessageBean<?> query(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String userCode, String corpCode, String month, Integer corpType, String staffName,
                                Integer assessmentType, Integer fstatusflag, Integer page, Integer pageSize) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.list(userCode, corpCode, month, corpType, staffName, assessmentType, fstatusflag, page, pageSize);
    }

    @ApiOperation("打分")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "staffCode", value = "打分人code",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "staffName", value = "打分人name", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "note", value = "备注",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "score", value = "分数",  paramType = "query", dataType = "float"),
            @ApiImplicitParam(name = "id", value = "单据id",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "nextStaff", value = "下一个打分人",  paramType = "query", dataType = "String")})
    @RequestMapping(value = "/score.htm", method = {RequestMethod.POST})
    @Log(title = "安全主任考核打分", businessModule = "安全主任考核", businessManipulation = BusinessManipulation.UPDATE)
    public MessageBean<?> score(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String staffCode, String staffName, String note, Float score, String id, String nextStaff) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.score(staffCode, staffName, note, score, id, nextStaff);
    }

    @ApiOperation("提交")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nextStaff", value = "打分人code",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "id", value = "id",  paramType = "query", dataType = "String")})
    @RequestMapping(value = "/submit.htm", method = {RequestMethod.POST})
    @Log(title = "安全主任考核打分提交", businessModule = "安全主任考核", businessManipulation = BusinessManipulation.UPDATE)
    public MessageBean<?> submit(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String nextStaff, String id) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.submit(id, nextStaff);
    }

}
